<template>
  <div v-if="Object.keys(detailInfo).length !== 0" class="goods-info">
    <div class="info-desc clear-fix">
      <div class="left"></div>
      <div class="desc">{{ detailInfo.desc }}</div>
      <div class="right"></div>
    </div>
    <div class="info-key">{{ detailObject.key }}</div>
    <div class="info-list">
      <img
        v-for="(item, index) in detailObject.list"
        :key="index"
        v-lazy="item"
        alt=""
        @load="imgLoad"
      />
    </div>
  </div>
</template>

<script>
export default {
  name: "DetailGoodsInfo",
  props: {
    detailInfo: {
      type: Object,
      default() {
        return {};
      },
    },
  },
  data() {
    return {
      counter: 0,
      imagesLength: 0,
    };
  },
  computed: {
    detailObject() {
      return this.detailInfo.detailImage[0];
    },
  },

  mounted() {},

  methods: {
    imgLoad() {
      if (++this.counter === this.imagesLength) {
        this.$emit("imageLoad");
      }
    },
  },
  watch: {
    detailInfo() {
      // 获取图片的个数
      this.imagesLength = this.detailInfo.detailImage[0].list.length;
    },
  },
};
</script>

<style lang="less" scoped>
.goods-info {
  padding: 20px 0;
  border-bottom: 5px solid #f2f5f8;
}

.info-desc {
  padding: 0 15px;
  .left,
  .right {
    width: 90px;
    height: 1px;
    background-color: #a3a3a5;
    position: relative;
  }
  .right::after {
    right: 0;
  }
  .left::before,
  .right::after {
    content: "";
    // display: block;
    position: absolute;
    width: 5px;
    height: 5px;
    background-color: #333;
    bottom: 0;
  }
  .desc {
    padding: 15px 0;
    font-size: 14px;
  }
}
.info-key {
  margin: 10px 0 10px 15px;
  color: #333;
  font-size: 15px;
}

.info-list img {
  width: 100%;
}
</style>
